package com.ossean.projectmanager.lasttabledao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ossean.projectmanager.model.RelativeMemoToOpenSourceProject;

public interface RelativeMemoToOpenSourceProjectDao {

	// 读取项目id对应的匹配权重较大的所有关联的帖子
	@Select("select * from ${targetTableName} where osp_id = #{osp_id} and match_weight > 2")
	public List<RelativeMemoToOpenSourceProject> getHighWeightMatchResult(
			@Param("osp_id") int osp_id,
			@Param("targetTableName") String targetTableName);

	// 批量读取匹配结果
	@Select("select * from ${targetTableName} where has_synchronized = 0 limit #{batch} ")
	public List<RelativeMemoToOpenSourceProject> getMatchResultsByHassync(@Param("targetTableName") String targetTableName,
				@Param("batch") int batch);

	// 删除指定项目的所有匹配结果
	@Delete("delete from ${targetTableName} where osp_id = ${ospId}")
	public void deleteMatchResult(
			@Param("targetTableName") String targetTableName,
			@Param("ospId") int ospId);
	
	//同步匹配结果表冗余
	@Update("update ${targetTableName} set replies_num = #{rmtosp.replies_num}, view_num_crawled = #{rmtosp.view_num_crawled}, "
			+ "memo_type = #{rmtosp.memo_type}, has_synchronized = 1, created_time = #{rmtosp.created_time} where id = #{rmtosp.id}")
	public void syncMatchResult(@Param("targetTableName") String targetTableName, @Param("rmtosp") RelativeMemoToOpenSourceProject rmtosp);
	
	// 读取项目id对应的匹配权重较大的所有关联的帖子
	@Select("select count(*) from ${targetTableName} where has_synchronized = 0")
	public int getNotSyncCount(
			@Param("targetTableName") String targetTableName);
}
